/*
 *  Copyright 2016 http://www.kedacomframework.org
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.kedacom.ctsp.authority.controller;

import com.kedacom.ctsp.authority.constant.AccessLoggerConstant;
import com.kedacom.ctsp.authority.constant.AuthorizeConstant;
import com.kedacom.ctsp.authority.entity.Person;
import com.kedacom.ctsp.authority.service.PersonService;
import com.kedacom.ctsp.authority.vo.AuthorityImportExcelResultVo;
import com.kedacom.ctsp.authority.vo.PersonVO;
import com.kedacom.ctsp.authz.Authorize;
import com.kedacom.ctsp.logging.AccessLogger;
import com.kedacom.ctsp.web.controller.AbstractCrudController2;
import com.kedacom.ctsp.web.controller.message.ResponseMessage;
import com.kedacom.ctsp.web.entity.page.PagerResult;
import com.kedacom.ctsp.web.entity.param.QueryParamEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 人员管理
 *
 * @author
 */
@ResponseBody
@RequestMapping("person")
@AccessLogger(AccessLoggerConstant.Module.PERSON)
@Authorize(resources = AuthorizeConstant.AUTH_PERSON)
@Api(tags = "Person", description = "人员管理")
public class AuthorityPersonController extends AbstractCrudController2<Person, String, PersonVO, PersonService> {

    @PostMapping("import")
    @ApiOperation("人员导入")
    public ResponseMessage<AuthorityImportExcelResultVo> importExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
        return ResponseMessage.ok(getService().importPerson(file, request));
    }

    @Authorize(resources = AuthorizeConstant.AUTH_PERSON_QUERY)
    @Override
    public ResponseMessage<PagerResult<PersonVO>> list(QueryParamEntity param, HttpServletRequest request) {
        return super.list(param, request);
    }

    @Authorize(resources = AuthorizeConstant.AUTH_PERSON_UPDATE)
    @Override
    public ResponseMessage<String> updateByPrimaryKey(@PathVariable String id, @RequestBody PersonVO data) {
        return super.patchByPrimaryKey(id, data);
    }

    @Authorize(resources = AuthorizeConstant.AUTH_PERSON_ADD)
    @Override
    public ResponseMessage<String> add(@RequestBody PersonVO data) {
        return super.add(data);
    }
}
